import 'package:flutter/cupertino.dart';
import 'package:yuellyfactory/util/StorageUtil.dart';

class AuthUtil{


  static const String Menu_Base_Manage="Base_Manage";
  static const String Menu_Model_Manage="Model_Manage";
  static const String Menu_Purchase_Manage="Purchase_Manage";
  static const String Menu_Price_Select="Price_Select";
  static const String Menu_Supplier_Manage="Supplier_Manage";


  //新建编辑删除
  static const  String Base_Type_Create="Base_Type_Create";
  static const String Base_Type_Delete="Base_Type_Delete";
  static const String Base_Type_Edit="Base_Type_Edit";
  static const String Base_Brand_Create="Base_Brand_Create";
  static const String Base_Brand_Delete="Base_Brand_Delete";
  static const String Base_Brand_Edit="Base_Brand_Edit";
  static const String Base_Serial_Create="Base_Serial_Create";
  static const String Base_Serial_Delete="Base_Serial_Delete";
  static const String Base_Serial_Edit="Base_Serial_Edit";
  static const String Base_Model_Create="Base_Model_Create";
  static const String Base_Model_Delete="Base_Model_Delete";
  static const String Base_Model_Edit="Base_Model_Edit";
  static const String Base_Material_Create="Base_Material_Create";
  static const String Base_Material_Delete="Base_Material_Delete";
  static const String Base_Material_Edit="Base_Material_Edit";

  //实时参数
  static const String Base_Globalparm_Create="Base_Globalparm_Create";
  static const String Base_Globalparm_Delete="Base_Globalparm_Delete";
  static const String Base_Globalparm_Edit="Base_Globalparm_Edit";

  //系列概况参数
  static const String Base_Globalserial_Create="Base_Globalserial_Create";
  static const String Base_Globalserial_Delete="Base_Globalserial_Delete";
  static const String Base_Globalserial_Edit="Base_Globalserial_Edit";


  //型号概况参数
  static const String Base_Partremark_Create="Base_Partremark_Create";
  static const String Base_Partremark_Delete="Base_Partremark_Delete";
  static const String Base_Partremark_Edit="Base_Partremark_Edit";

  //型号参数
  static const String Base_Partparm_Create="Base_Partparm_Create";
  static const String Base_Partparm_Edit="Base_Partparm_Edit";
  static const String Base_Partparm_Delete="Base_Partparm_Delete";

  //编辑零件参数
  static const String Base_Materialparm_Edit="Base_Materialparm_Edit";

  //价格权限
  static const String Base_Price="Base_Price";


  // 静态实例
  static final AuthUtil _instance = AuthUtil._internal();

  // 工厂构造函数，返回唯一实例
  factory AuthUtil() {
    return _instance;
  }

  // 私有构造函数，防止外部实例化
  AuthUtil._internal();


  static AuthUtil get instance =>_instance;


   List<String> menuList=[];
   List<String> btnList=[];


   void initDatas(){
     {
       var menu= StorageUtil.getMenu();
       if(menu!=null){
         menuList=[];
         for(var item in menu){
           var menuCode=item["menuCode"];
           menuList.add(menuCode);
         }
       }
     }
    {
      var menu= StorageUtil.getMenuButton();
      if(menu!=null){
        btnList=[];
        for(var item in menu){
          var menuCode=item["menuCode"];
          btnList.add(menuCode);
        }
      }
    }

   }




   bool checkMenu(String auth){
     return menuList.contains(auth);
   }


  bool checkMenuBtn(String auth){
    return btnList.contains(auth);
  }


  Widget getMenuWidget(String auth,Widget child){
     return Visibility(
         visible: checkMenu(auth),
         child: child);
  }
  Widget getMenuBtnWidget(String auth,Widget child){
    return Visibility(
        visible: checkMenuBtn(auth),
        child: child);
  }


}